package com.test.daily.leetcode.y2022.m06.day0625.v03;

import java.util.Arrays;

/**
 * @author Tom on 2022/6/25
 */
public class Solution {
    public int minCost(int[][] cost){
        int[] dp = new int[3];
        for(int i = 1; i < cost.length; i++){
            int[] dpNew = new int[3];
            for(int j = 0; j < 3; j ++){
                dpNew[j] = Math.min(dp[(j+1)%3], dp[(j+2)%3]) + cost[i][j];
            }
            dp = dpNew;
        }
        return Arrays.stream(dp).max().getAsInt();
    }
}
